vim.api.nvim_create_autocmd("FileType", { pattern = "json", command = "set filetype=jsonc" })
vim.api.nvim_create_autocmd("FileType", { pattern = "zsh", command = "set filetype=sh" })

vim.api.nvim_create_autocmd({ "FocusLost" }, {
	pattern = "*",
	callback = function(event)
		if event.buftype or event.file == "" then
			return
		end
		if vim.api.nvim_buf_get_option(event.buf, "modified") then
			vim.api.nvim_buf_call(event.buf, function()
				vim.schedule(function()
					vim.cmd("silent! write")
					-- vim.notify("Autosaved!", vim.log.levels.INFO, {})
				end)
			end)
		end
	end,
})


local nvimrc = vim.api.nvim_create_augroup("NVIMRC", {clear = true})
vim.api.nvim_create_autocmd({"BufWritePost"}, {
    pattern = "init.lua",
    group = nvimrc,
    command = "source %"
})
vim.api.nvim_create_autocmd({"BufWritePost"}, {
    pattern = "init.lua",
    group = nvimrc,
    callback = function()
      vim.o.path = vim.o.path .. ",**/*"
    end
})

